package org.liveboardgames.agricola.control.commands
{
    import com.adobe.cairngorm.commands.ICommand;
    import com.adobe.cairngorm.control.CairngormEvent;
    
    import org.liveboardgames.agricola.control.delegates.AddResourceDelegate;
    import org.liveboardgames.agricola.control.events.AddResourceEvent;
    
    import mx.controls.Alert;
    import mx.rpc.IResponder;
    import mx.rpc.events.FaultEvent;
    
    public class AddResourceCommand implements ICommand, IResponder
    {
        public function execute(event:CairngormEvent):void
        {
            var delegate:AddResourceDelegate = new AddResourceDelegate(this);
            var addResourceEvent:AddResourceEvent = AddResourceEvent(event);
            delegate.addResource(addResourceEvent.resourceHost, addResourceEvent.resources);
        }
        
        public function result(data:Object):void
        {
            // Do nothing, the model should be updated by the delegate
        }
        
        public function fault(info:Object):void
        {
            var faultEvent:FaultEvent = FaultEvent(info);
            Alert.show("Could not add new resources", "Error");
        }
    
    }
}